      <div class="templatemo-content-wrapper">
        <div class="templatemo-content">
          <ol class="breadcrumb">
            <li><a href="<?=site_url()?>/cost/index">成本分析</a></li>
            <li class="active">支出列表</li>
          </ol>
          <div class="row margin-bottom-5">
            <div class="col-md-12">
              <ul class="nav nav-pills">
                <li class="active"><a href="<?=site_url()?>/cost/add">添加支出</a></li>
                <li class="active"><a href="<?=site_url()?>/cost/lostindex">库存损耗管理</a></li>
              </ul>          
            </div>
            <hr />
            <div class="col-md-12">
            	开始日期
            	<input type="text" id="startdate" name="startdate" value="2015-08-11">
            	结束日期
            	<input type="text" id="enddate" name="enddate" value="<?php echo date('Y-m-d',time()); ?>">
            	<button class="btn btn-primary" id="submit_btn">导出成本分析</button>
            	<button class="btn btn-primary" id="order_btn">导出采购统计</button>
            	<button class="btn btn-primary" id="sale_btn">导出销售表</button>
            	<a href="<?=site_url()?>/cost/salelist" class="btn btn-primary">查看销售量</a>
            </div>
            <div class="col-md-12">
            	<input type="text" id="name" name="name" value="">
            	<button class="btn btn-primary" id="search_btn">搜索</button>
            </div>
          </div> 
          <div class="row">
            <div class="col-md-12">
        
              <div class="table-responsive">
                <h4 class="margin-bottom-15">支出列表</h4>
                <table class="table table-striped table-hover table-bordered">
                  <thead>
                    <tr>
                      <th>ID</th>
                      <th>商品名称</th>
                      <th>进货价</th>
                      <th>数量</th>
                      <th>总价</th>
                      <th>进货时间</th>
                      <th>备注</th>
                      <th>操作</th>
                    </tr>
                  </thead>
                  <tbody>
                  	<?php foreach ($costs as $item):?>
                    <tr>
                      <td><?php echo $item['id'];?></td>
                      <td><?php echo $item['name'];?></td>
                      <td>
                      		<?php 
                      		if(!empty($item['price'])){
                      			echo $item['price'].'元/'.$item['unit'];
                      		}else{
                      			echo '';
                      		}
                      		?>
                      	</td>
                      <td><?php echo $item['amount'];?></td>
                      <td><?php echo $item['total'].'元';?></td>
                     <td><?php echo $item['cost_time'];?></td>
                     <td><?php echo $item['note'];?></td>
                     <td><a href="#" class="btn btn-link del" data-id="<?php echo $item['id'];?>" >删除</a></td>
                    </tr>
                     <?php endforeach;?>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
           <div class="pagination">
           		<?php echo $links ;?>
           </div>
        </div>
      </div>
    <script>
	$(document).ready(function() {
		$('#startdate').datepicker({
			dateFormat: 'yy-mm-dd',
			monthNames: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
			dayNamesMin: ['日','一','二','三','四','五','六']
		});
		$('#enddate').datepicker({
			dateFormat: 'yy-mm-dd',
			monthNames: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
			dayNamesMin: ['日','一','二','三','四','五','六']
		});
		$("#submit_btn").click(function() {
			var startdate = $("#startdate").val();
			var enddate = $("#enddate").val();
			var url = "<?php echo site_url('cost/exportCosts')?>";
			window.location.href=url+"/startdate/"+startdate+"/enddate/"+enddate;
		});
		$("#order_btn").click(function() {
			var startdate = $("#startdate").val();
			var enddate = $("#enddate").val();
			var url = "<?php echo site_url('order/exportOrderdetail')?>";
			window.location.href=url+"/startdate/"+startdate+"/enddate/"+enddate;
		});
		$("#sale_btn").click(function() {
			var startdate = $("#startdate").val();
			var enddate = $("#enddate").val();
			var url = "<?php echo site_url('cost/exportSales')?>";
			window.location.href=url+"/startdate/"+startdate+"/enddate/"+enddate;
		});
		$("#search_btn").click(function() {
			var name = $("#name").val();
			if(name==""||name==null){
				name="empty";
			}
			var url = "<?php echo site_url('cost/index')?>";
			window.location.href=url+"/name/"+name;
		});
		$("#name").keydown(function(e) {
			if(e.keyCode == 13) {
				var name = $("#name").val();
				if(name==""||name==null){
					name="empty";
				}
				var url = "<?php echo site_url('cost/index')?>";
				window.location.href=url+"/name/"+name;
			}
		});
		$(".del").click(function() {
			if(confirm("确定要删除该数据吗？"))
			{
			var id = $(this).attr("data-id");
			$.ajax({
				url : '<?php echo site_url('cost/delete')?>',
				type : "post",
				async : true,
				data : {
					'id' : id
				},
				dataType : "json",
				timeout : "1000",
				error : function() {
					alert("服务加载出错");
				},
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						window.location.reload();
					}else{
						alert(data.msg);
					}
				}
			});
			}
		});
	}); 
</script>